﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using winform = System.Windows.Forms;
namespace My_LoadPE.Common
{
    public sealed class ReadFile
    {
        private ReadFile()
        {

        }
        public static ReadFile Instance => Inner.innerclass;
        private class Inner
        {
            static Inner()
            {

            }
            public static readonly ReadFile innerclass = new ReadFile();
        }

        public async Task<byte[]> BinnaryFile(string filepath = "EXE")
        {
            winform.OpenFileDialog fileDialog = new winform.OpenFileDialog();
            fileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + filepath;
            fileDialog.Filter = "*.exe|";
            if (fileDialog.ShowDialog() == winform.DialogResult.OK)
            {
                using (FileStream file = new FileStream(fileDialog.FileName, FileMode.Open))
                {
                    if (file.CanRead)
                    {
                        file.Position = 0;
                        byte[] allbyte = new byte[file.Length];
                        await file.ReadAsync(allbyte, 0, allbyte.Length).ConfigureAwait(false);

                        return allbyte;
                    }
                }
            }
            return null;
        }
    }
}
